/*
 * @Author: 清香白莲 1243327527@qq.com
 * @Date: 2023-09-07 17:16:47
 * @LastEditors: 清香白莲 1243327527@qq.com
 * @LastEditTime: 2023-09-08 14:23:11
 * @FilePath: /shang_study/src/store/search.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { reqPostSearch } from '@/api';

export default {
    namespaced: true,
    actions: {
        async searchList(content, value) {
            let params = value || {};
            let result = await reqPostSearch(params);
            if (result.code === 200) {
                content.commit('SEARCHLIST', result.data);
            }else {
                content.commit('SEARCHLIST', {});
            }
        },
    },
    mutations: {
        SEARCHLIST(state, searchObj) {
            state.searchObj = searchObj;
        }
    },
    state: {
        searchObj: {},
    },
    // 计算属性
    // 项目当中getters主要的作用是：简化仓库中的数据（简化数据而生）
    // 可以把我们将来在组件当中需要用的数据简化一下【将来获取数据的时候更加的方便了】
    getters: {
        goodsList(state) {
            return state.searchObj.goodsList || [];
        },
        trademarkList(state) {
            return state.searchObj.trademarkList || [];
        },
        attrsList(state) {
            return state.searchObj.attrsList || [];
        },
    },
}
